package main

import (
	"fmt"
	"math"
)

func main() {
	testlist := []int{1,3,5,7,9,11,13,15,17,19}
	key :=binary_search(testlist,3)
	fmt.Println("二分查找得答案为：",key)
}

func binary_search(list []int,item int)int{
	low := 0
	high := len(list) - 1
	for low <= high {
		mid := int(math.Floor(float64((low + high)/2)))
		guess := list[mid]
		if guess == item {
			return mid
		}else if guess >item {
			high = mid - 1
		}else {
			low = mid + 1
		}
	}
	return 0
}
